package hw;

import java.util.*;
import java.util.stream.Collectors;

public class Solution01 {

    public int[] twoSum(int[] nums, int target) {
        int[] result = new int[2];
        if (nums.length == 2) {
            result[1] = 1;
            return result;
        }
        List<Integer> collect = Arrays.stream(nums).boxed().collect(Collectors.toList());
        for (int i = 0; i < collect.size(); i++) {
            result[0] = i;
            int j = target - nums[i];
            if (collect.contains(j) && collect.indexOf(j) != i) {
                result[1] = collect.indexOf(j);
                break;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Solution01 solution01 = new Solution01();
        int[] nums = new int[]{3, 2, 4};
        int target = 6;
        Arrays.stream(solution01.twoSum(nums, target)).forEach(System.out::println);
    }
}
